package partB;

import evolution_superclasses.Genotype;
import binary_evolution.Binary_Genetic_Operators;

public class B_Genetic_Operators extends Binary_Genetic_Operators {
	private double _valueMutationRate = -1;

	public B_Genetic_Operators(int size) {
		super(size);
	}

	public double get_valueMutationRate() {
		return _valueMutationRate;
	}

	public void set_valueMutationRate(double bitMutationRate) {
		_valueMutationRate = bitMutationRate;
	}

	@Override
	public void mutation(Genotype gen) {
		if(_valueMutationRate < 0)_valueMutationRate = 0.05;
		for(int i = 0; i < _genSize; i+=4){
			if(_valueMutationRate > _rand.nextDouble()){
				int value = _rand.nextInt(10);
				((B_Genotype)gen).editBinaryArray(i, (value&1)==1);
				((B_Genotype)gen).editBinaryArray(i+1, (value&2)==2);
				((B_Genotype)gen).editBinaryArray(i+2, (value&4)==4);
				((B_Genotype)gen).editBinaryArray(i+3, (value&8)==8);
			}
		}
	}

}
